package com.aiju.cash.core.api;

import com.aiju.app.config.ConfigManager;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.File;

/**
 * @author: 佐为
 * @date: 2016-11-25 09:28
 * @version: V1.0
 * @Description: 商品
 */
public class GoodApi {

    private String goodList = ConfigManager.INIT_SERVER_HOST + "/goods/list";
    private String goodSava = ConfigManager.INIT_SERVER_HOST + "/goods/save";
    private String goodUpdate = ConfigManager.INIT_SERVER_HOST + "/goods/update";
    private String goodDelete = ConfigManager.INIT_SERVER_HOST + "/goods/delete";
    private String goodDetails = ConfigManager.INIT_SERVER_HOST + "/goods/get";
    private String listWithGoods = ConfigManager.INIT_SERVER_HOST + "/goodsType/listWithGoods";
    private String upload = ConfigManager.INIT_SERVER_HOST + "/goods/upload";

    /**
     * 商品列
     *
     * @param token       令牌
     * @param goodsTypeId 商品类型id
     * @param currentNum  当前页
     * @param currentNum  每一页显示个数
     */
    public void goodList(String goodsTypeId, String currentNum, String pageSize, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(goodList)
                .addParams("goodsTypeId", goodsTypeId)
                .addParams("currentNum", currentNum)
                .addParams("pageSize", pageSize)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 商品添加
     *
     * @param token       令牌
     * @param name        商品名称
     * @param price       商品价格
     * @param goodsTypeId 商品类型id
     * @param code        商品条形码
     * @param imageUrl    商品图片地址
     */
    public void goodSava(String storeId, String name, String goodsTypeId, String price, String unit, String token, String code, String imageUrl, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(goodSava)
                .addParams("storeId", storeId)
                .addParams("name", name)
                .addParams("goodsTypeId", goodsTypeId)
                .addParams("token", token)
                .addParams("price", price)
                .addParams("unit", unit)
                .addParams("code", code)
                .addParams("imageUrl", imageUrl)
                .build()
                .execute(callback);
    }


    /**
     * 商品修改
     *
     * @param id          商品id
     * @param token       令牌
     * @param name        商品名称
     * @param code        商品条码
     * @param price       商品价格
     * @param goodsTypeId 商品类型id
     * @param imageUrl    商品图片地址
     */
    public void goodUpdate(String id, String storeId, String token, String name, String code, String price, String unit,
                           String goodsTypeId, String imageUrl, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(goodUpdate)
                .addParams("id", id)
                .addParams("storeId", storeId)
                .addParams("token", token)
                .addParams("name", name)
                .addParams("code", code)
                .addParams("price", price)
                .addParams("unit", unit)
                .addParams("goodsTypeId", goodsTypeId)
                .addParams("imageUrl", imageUrl)
                .build()
                .execute(callback);
    }

    /**
     * 商品删除
     *
     * @param ids   商品id
     * @param token 令牌
     */
    public void goodDelete(String ids, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(goodDelete)
                .addParams("ids", ids)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 商品详情
     *
     * @param id    商品id
     * @param token 令牌
     */
    public void goodDetails(String id, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(goodDetails)
                .addParams("id", id)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 商品详情
     *
     * @param storeId 店铺id
     * @param token   令牌
     */
    public void listWithGoods(String storeId, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(listWithGoods)
                .addParams("storeId", storeId)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 商品图片上传
     *
     * @param storeId 图片文件
     * @param token  令牌
     */
    /**
     * 店铺上传头像
     */
    public void uploadGoodImage(File file, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(upload)
                .addFile("uploadFile", "cropImage.jpeg", file)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

}
